package com.itcam.ioc_04;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class JavaBean {

    /**
     * <bean id class
     * <property  name="name" value="Cammy"
     */

    // 方案1：直接赋值
    private String name = "Cammy";

    // 方案2：注解赋值 @Value注解 ————> 读取外部配置
    @Value("24")
    private int age;

    // 方案2使用场景
    @Value("${jdbc.username:admin}") // 默认值语法 @Value(${key:value默认值})
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Override
    public String toString() {
        return "JavaBean{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
